﻿using OA.Core;
using OA.Core.Helper;
using OA.Core.Other;
using OA.Model.MyAttribute;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
//using System.Web.DynamicData;

namespace OA.Model
{
    //one two three four five six
    public enum VoucherType
    {
        [Description("待申请")]
        Zero = 0,

        [Description("已发起")]
        One = 1,

        [Description("撤回")]
        Two = 2,

        [Description("审核不通过")]
        Three = 3,

        [Description(" 已审核")]
        Four = 4,

        [Description("申请作废中")]
        Five = 5,

        [Description("已作废")]
        Six = 6,
       
    }


    //[TableName("申请表单")]
    //[Table("Voucher")]
    public class Voucher : BaseInfo
    {
        /// <summary>
        /// -1 被删除   0 待发起  1 已发起 2:撤回 3 审核不通过 4 已审核 5 申请作废中 6 已作废
        /// </summary>
        [Display(Name = "状态")]
        [Description("-1 被删除   0 待发起  1 已发起 2:撤回 3 审核不通过 4 已审核 5 申请作废中 6 已作废")]
        public int Status { get; set; }

        [NotMapped]
        public string StatusName { get { return MyEnum.GetEnumNameByValue(this.Status, typeof(VoucherType)); } }

        /// <summary>
        /// 单据号
        /// </summary>
        [Display(Name = "单据号")]
        [MaxLength(20)]
        [Required]
        public string No { get; set; }

       // [Index("CustomForm_Sponsor", order:1)]
       // [Index("CustomFormID")]
        
        [NotMapped]
        public int CustomFormID { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        [MaxLength(50)]
        [Required]
        [Display(Name ="主题")]
        [Tag(TagEnum.Text, "required", "标题", 3, 50)]
        public string Title { get; set; }

        /// <summary>
        /// 申请时间
        /// </summary>         
        public DateTime? ApplicationDate { get; set; }

        /// <summary>
        /// 岗位ID
        /// </summary>
        [Tag(TagEnum.Select,"","","")]
        [Display(Name = "主办岗位")]
        public int PositionID { get; set; }

        /// <summary>
        /// 主办人工号
        /// </summary>
        [Tag(TagEnum.Select, "", "", "")]
        [MaxLength(10)]
       // [Index("CustomForm_Sponsor", order: 2)]
        [Display(Name = "主办人")]
        public string Sponsor { get; set; }         

        

        /// <summary>
        /// 主办部门
        /// </summary>
        [Tag(TagEnum.Select, "", "", "")]
        [Display(Name = "主办部门")]
        public int DepartmentID { get; set; }

         

 

        [MaxLength(100)]
        public string SupervisingEmpID { get; set; }


        /// <summary>
        /// 扩展内容
        /// </summary>
        public string Extension { get; set; }


        /// <summary>
        /// 主办部门
        /// </summary>
        [MaxLength(200)]
        public string DepartmentName { get; set; }

        /// <summary>
        /// 主办岗位
        /// </summary>
        [NotMapped]
        public string PositionName { get; set; }

        /// <summary>
        /// 主办人
        /// </summary>
        [MaxLength(20)]
        public string SponsorName { get; set; }
        
 
 

        /// <summary>
        /// 审批流程
        /// </summary>
        [NotMapped]
        public List<ApprovalItem> ApprovalItems { get; set; }

        /// <summary>
        /// 单据完结时间
        /// </summary>
        public DateTime? FinishTime { get; set; }

        /// <summary>
        /// 自定义流程  及 会签节点数据 
        /// </summary>
        [MaxLength(3000)]
        public string TreeContent { get; set; }

        public string ApprovalNodeContent { get; set; }

        [NotMapped]
        public bool HasHuiQian { get; set; } = false;

        [NotMapped]
        public List<CustomProcessNode> CustomProcessNodes { get { return JsonHelper.DeserializeList<CustomProcessNode>(this.TreeContent); }}

        /// <summary>
        /// 备注
        /// </summary>
        [Display(Name = "备注")]
        [MaxLength(100)]
        public string Remark { get; set; }

        /// <summary>
        /// 审批完成后生成的PDF路径
        /// </summary>
        [MaxLength(100)]
        public string PdfUrl { get; set; }

         
        public int PdfStatus { get; set; }

        /// <summary>
        /// 表单结果
        /// </summary>
        [NotMapped]
        public Dictionary<string,string> Result { get; set; }

        /// <summary>
        /// 表单结构
        /// </summary>
        public string CustomFormContent { get; set; }


        public int? ApprovalID { get; set; }

    }

    public class ReferencesVoucher
    {
        public int ID { get; set; }
        public int CustomFormID { get; set; }

        public int FormID { get; set; }
        public string No { get; set; }

        public string Title { get; set; }


        public static Expression<Func<Voucher, ReferencesVoucher>> ReferencesMap = m => new ReferencesVoucher()
        {
            FormID = m.ID,
            Title = m.Title,
            No=m.No,
            ID=m.ID
        };
    }
   



    public class SimpleVoucher : SimpleInfo
    {
        /// <summary>
        /// -1 被删除 0 草稿  1 待申请 2:审核中 4 审核不通过 8 需沟通 16 已撤回 32 申请作废中 64 已作废  128 审核完成
        /// </summary>
        public new int Status { get; set; }

        public string StatusName { get { return MyEnum.GetEnumNameByValue(this.Status, typeof(VoucherType)); } }

        public string Title { get; set; }

        public string No { get; set; }

        public DateTime? FinishTime { get; set; }

        public DateTime? ApplicationDate { get; set; }

        public string CurrentApprover { get; set; }

        public string Communicator { get; set; }

        public int CustomFormID { get; set; }

        public string Sponsor { get; set; }

        public string SponsorName { get; set; }

        public string Remark { get; set; }

        public DateTime CreateDateTime { get; set; }



        public static Expression<Func<Voucher, SimpleVoucher>> Map = m => new SimpleVoucher()
        {
            ID = m.ID,
            No = m.No,
            Title = m.Title,
            Status=m.Status,
            FinishTime=m.FinishTime,
            ApplicationDate=m.ApplicationDate,
            CustomFormID=m.CustomFormID,
            SponsorName = m.SponsorName,
            CreateDateTime=m.CreateDateTime
        };

        public static Expression<Func<Voucher, SimpleVoucher>> NOMap = m => new SimpleVoucher()
        {
            ID = m.ID,
            No = m.No             
        };

        

        public static Expression<Func<Voucher, SimpleVoucher>> Map_Manage = m => new SimpleVoucher()
        {
            ID = m.ID,
            No = m.No,
            Title = m.Title,
            Status = m.Status,
            FinishTime = m.FinishTime,
            ApplicationDate = m.ApplicationDate,
            Sponsor= m.Sponsor,
            SponsorName=m.SponsorName,
            Remark=m.Remark
        };

    }

    public class CountersignEmployeeAPi
    {
        public string Value { get; set; }

        public string EmpName { get; set; }
    }



    public class CountersignEmployee
    {
        public int Status { get; set; } = 1;

        public string EmpID { get; set; }

        public int PositionID { get; set; }

        public int DepartmentID { get; set; }

        public string DepatrmentName { get; set; }

        public string PositionName { get; set; }

        public string EmpName { get; set; }

        public int Step { get; set; }

        public string DepartmentPath { get; set; }
    }


    public class CustomProcessNode
    {
        public int Status { get; set; } = 1;

        public string EmpID { get; set; }

        public int PositionID { get; set; }

        public int DepartmentID { get; set; }

        public string DepatrmentName { get; set; }

        public string PositionName { get; set; }

        public string EmpName { get; set; }

        public int Setp { get; set; }
    }


    ///单据项结果 
    public class ExtensionResultItem
    {
        /// <summary>
        ///  属性名称
        /// </summary>
        public string Attribute { get; set; }

        /// <summary>
        /// 类型
        /// </summary>
        public int Type { get; set; }

        /// <summary>
        /// 是否汇总列
        /// </summary>
        public bool IsSummarizing { get; set; }

        /// <summary>
        /// 值类型
        /// </summary>
        public string Value { get; set; }

        /// <summary>
        /// 表单类型
        /// </summary>
        public List<Dictionary<string,string>> List { get; set; }

    }




}
